/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import java.io.IOException;
import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

/**
 *
 * @author zimi
 */
public class Measure {

    public static final Measure getKilogram() { return new Measure("kilogram", "1"); }

    public static final Measure getDecagram() { return new Measure("dekagram", "1"); }

    public static final Measure getGram() { return new Measure("gram", "1"); }

    public static final Measure getLitre() { return new Measure("litr", "1"); }

    public static final Measure getMililitre() { return new Measure("mililitr", "1"); }
    
    public static final Measure getUnit() { return new Measure("sztuka", "1"); }

    public static final Measure getNoUnit() { return new Measure(""); }

    public static final Measure getGram100() { return new Measure("gram", "100");}//Measure.getGram().multiply(100); }

    public static final Measure getMililitre100() { return new Measure("mililitr","100");}//Measure.getMililitre().multiply(100); }

    private String name;

    private String amount;

    public Measure(){
        
    }
    
    public Measure(String name, String amount) {
        this.name = name;
        this.amount = amount;
    }

    public Measure (String name){
        this.name = name;
    }

    public Measure(KXmlParser parser) throws XmlPullParserException, IOException {
        while (parser.nextTag() != XmlPullParser.END_TAG) {
            parser.require(XmlPullParser.START_TAG, null, null);
            String unitAmountName = parser.getName();
            String unitAmountText = parser.nextText();
            if (unitAmountName.equals("name")) {
                this.name = unitAmountText;
            }
            if (unitAmountName.equals("amount")) {
                //this.amount = Double.parseDouble(unitAmountText);
                this.amount = unitAmountText;
            }
            parser.require(XmlPullParser.END_TAG, null, null);
        }
    }

    public String getAmount() {
        return amount;
    }

    public String getName() {
        return name;
    }

//    public Measure multiply(double multiplier) {
//        Measure m = new Measure(name, amount*multiplier);
//        return m;
//    }
 
}
